package com.bot.devbot.service.feishu;

import cn.hutool.json.JSONUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Arrays;
import java.util.List;

/**
 * 飞书富文本对象结构,暂未使用
 *
 * @author xialiguo
 * @version 1.0
 * @date 2025/1/22 15:03
 * @since 1.0
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class NotificationMessage {
    private String msg_type;
    private Content content;

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class Content {
        private Post post;

        @Data
        @NoArgsConstructor
        @AllArgsConstructor
        public static class Post {
            private ZhCn zh_cn;

            @Data
            @NoArgsConstructor
            @AllArgsConstructor
            public static class ZhCn {
                private String title;
                private List<List<Element>> content;

                @Data
                @NoArgsConstructor
                @AllArgsConstructor
                public static class Element {
                    private String tag;
                    private String text;
                    private String href;
                    private String user_id;
                }
            }
        }
    }

    /**
     * 将对象转为 JSON 字符串
     *
     * @return JSON 字符串
     */
    public String toJsonString() {
        return JSONUtil.toJsonStr(this);
    }

    public static void main(String[] args) {
        // 示例对象构建
        NotificationMessage.Content.Post.ZhCn.Element textElement =
                new NotificationMessage.Content.Post.ZhCn.Element("text", "项目有更新: ", null, null);
        NotificationMessage.Content.Post.ZhCn.Element linkElement =
                new NotificationMessage.Content.Post.ZhCn.Element("a", "请查看", "http://www.example.com/", null);
        NotificationMessage.Content.Post.ZhCn.Element atElement =
                new NotificationMessage.Content.Post.ZhCn.Element("at", null, null, "ou_18eac8********17ad4f02e8bbbb");

        NotificationMessage.Content.Post.ZhCn zhCn = new NotificationMessage.Content.Post.ZhCn(
                "项目更新通知",
                Arrays.asList(Arrays.asList(textElement, linkElement, atElement))
        );

        NotificationMessage.Content.Post post = new NotificationMessage.Content.Post(zhCn);
        NotificationMessage.Content content = new NotificationMessage.Content(post);
        NotificationMessage message = new NotificationMessage("post", content);

        // 转为 JSON 字符串
        System.out.println(message.toJsonString());

    }
}
